
//% color="#FF6347" iconWidth=50 iconHeight=40
namespace LicensePlate{

    export function initmodel() {}
    //% block="输入待识别的图片为[STR]" blockType="command"
    //% STR.shadow="string" STR.defl="car.jpg"
    export function init(parameter: any, block: any) {
        let str=parameter.STR.code;

        Generator.addImport(`from LicensePlateProcessor import *`);
        Generator.addDeclaration("LicensePlateProcessor",`processor = LicensePlateProcessor()`);
        Generator.addCode(`image_file = ${str}`);
    }
    //% block="---"
    export function tag1() {}
    //% block="设置滑窗宽为[W]高为[H]步长为[S],启用滑窗检测定位车牌" blockType="command"
    //% W.shadow="number"    W.defl=180
    //% H.shadow="number"    H.defl=70
    //% S.shadow="number"    S.defl=18
    export function loadimage(parameter: any, block: any) {
        let w=parameter.W.code;
        let h=parameter.H.code;
        let s=parameter.S.code;
        Generator.addCode(`processor.sliding_window_detection(image_file,${w},${h},${s})`)

    }

    //% block="从图片中裁剪校正车牌图像并进行二值化处理" blockType="command"
    export function readplate(parameter: any, block: any) {
        Generator.addCode(`processor.crop_and_binarize(image_file)`)
    }



    //% block="对车牌图像进行字符分割并显示结果" blockType="command"
    export function setkernel(parameter: any, block: any) {

       Generator.addCode(`processor.character_segmentation()`)
 
    }
        //% block="---"
    export function tag2() {}
    //% block="输出车牌识别结果" blockType="reporter"
    export function result(parameter: any, block: any) {

       Generator.addCode(`processor.recognize_plate()`)
 
    }
}
 